<template>
  <div class="home-wrapper">
    <KoiCard></KoiCard>
  </div>
</template>

<script>
import KoiCard from "./components/KoiCard.vue";
// import PanelGroup from '@/views/components/PanelGroup'
// import { mapGetters } from 'vuex'
import CountTo from "vue-count-to";
// import { listWarnInventory } from "@/api/wms/inventory";
// import { listExpiryItem } from "@/api/wms/item";

export default {
  components: {
    // PanelGroup,
    CountTo,
    KoiCard,
  },
  data() {
    return {
      tableData: [
        {
          date: "1",
          name: "应急",
          address: "20",
        },
      ],
      nowTime: "",
      hello: "",
      warnList: [],
      expiryList: [],
      queryWarnParams: {
        pageNum: 1,
        pageSize: 10,
      },
      queryExpiryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      //预警条数
      totalWarn: 0,
      totalExpiry: 0,
      columns: [
        { key: 1, label: "编号", visible: true },
        { key: 2, label: "名称", visible: true },
        { key: 3, label: "分类", visible: true },
        { key: 4, label: "单位类别", visible: true },
        { key: 5, label: "所属货架", visible: false },
        { key: 6, label: "所属库区", visible: true },
        { key: 7, label: "所属仓库", visible: true },
        { key: 8, label: "安全库存", visible: true },
        { key: 9, label: "有效期", visible: true },
        { key: 11, label: "备注", visible: false },
      ],
      ifScroll: false,
    };
  },
  //   computed: {
  //     ...mapGetters([
  //       "avatar",
  //       "name",
  //       "areaList",
  //       "warehouseList",
  //       "supplierList",
  //       "customerList",
  //       "carrierList",
  //       "warehouseMap",
  //       "areaMap",
  //     ]),
  //   },
  created() {
    // this.showTimes()
    // this.helloTimes()
    // this.getWarnList()
    // this.getExpiryList()
  },
  methods: {
    getWarnList() {
      this.loading = true;
      const { pageNum, pageSize } = this.queryWarnParams;
      const pageReq = { page: pageNum - 1, size: pageSize };
      listWarnInventory(pageReq).then((response) => {
        const { content, totalElements } = response;
        this.warnList = content;
        this.totalWarn = totalElements;
        this.loading = false;
      });
    },
    getExpiryList() {
      this.loading = true;
      const { pageNum, pageSize } = this.queryExpiryParams;
      const pageReq = { page: pageNum - 1, size: pageSize };
      listExpiryItem(pageReq).then((response) => {
        const { content, totalElements } = response;
        content.forEach((item) => {
          item.warehouseName = this.warehouseMap.get(item.warehouseId);
        });
        content.forEach((item) => {
          item.areaName = this.areaMap.get(item.areaId);
        });
        this.expiryList = content;
        this.totalExpiry = totalElements;
        this.loading = false;
      });
    },
    timeFormate(timeStamp) {
      let year = new Date(timeStamp).getFullYear();
      let month =
        new Date(timeStamp).getMonth() + 1 < 10
          ? "0" + (new Date(timeStamp).getMonth() + 1)
          : new Date(timeStamp).getMonth() + 1;
      let date =
        new Date(timeStamp).getDate() < 10
          ? "0" + new Date(timeStamp).getDate()
          : new Date(timeStamp).getDate();
      let hh =
        new Date(timeStamp).getHours() < 10
          ? "0" + new Date(timeStamp).getHours()
          : new Date(timeStamp).getHours();
      let mm =
        new Date(timeStamp).getMinutes() < 10
          ? "0" + new Date(timeStamp).getMinutes()
          : new Date(timeStamp).getMinutes();
      let ss =
        new Date(timeStamp).getSeconds() < 10
          ? "0" + new Date(timeStamp).getSeconds()
          : new Date(timeStamp).getSeconds();
      let week = new Date(timeStamp).getDay();
      let weeks = ["日", "一", "二", "三", "四", "五", "六"];
      let getWeek = "星期" + weeks[week];
      this.nowTime = year + "年" + month + "月" + date + "日" + " " + getWeek;
    },
    showTimes() {
      this.timeFormate(new Date());
    },
    helloTimes() {
      let hh = new Date().getHours();
      if (0 < hh && hh < 12) {
        this.hello = "上午好";
      } else if (hh < 18) {
        this.hello = "下午好";
      } else {
        this.hello = "晚上好";
      }
    },
    handleGo(path) {
      this.$router.push(path);
    },
    goAnchor(elementName) {
      this.$refs[elementName].scrollIntoView({
        behavior: "smooth", // 平滑过渡
        block: "start", // 上边框与视窗顶部平齐。默认值
      });
    },
  },
};
</script>

<style scoped lang="scss">
</style>
